#include <stdio.h>
#include <stdlib.h>
void setIntArray(int arr[],int uplimit,int num)
{
    int i;
    for(i=0;i<num;i++)
    {
        arr[i]=(int)random() % uplimit; 
    }
}
void mergearray(int a[], int first, int mid, int last, int temp[])  
{  
    int i = first, j = mid + 1;  
    int m = mid,   n = last;  
    int k = 0;  
      
    while (i <= m && j <= n)  
    {  
        if (a[i] <= a[j])  
            temp[k++] = a[i++];  
        else  
            temp[k++] = a[j++];  
    }  
      
    while (i <= m)  
        temp[k++] = a[i++];  
      
    while (j <= n)  
        temp[k++] = a[j++];  
      
    for (i = 0; i < k; i++)  
        a[first + i] = temp[i];  
}  
void mergesort(int a[], int first, int last, int temp[])  
{  
    if (first < last)  
    {  
        int mid = (first + last) / 2;  
        mergesort(a, first, mid, temp);      
        mergesort(a, mid + 1, last, temp);   
        mergearray(a, first, mid, last, temp);   
    }  
}  
void MergeSort()
{
    int a[100],temp[100],i;
    setIntArray(a,10000,100);
    mergesort(a,0,99,temp);
    for(i=0;i<100;i++)
    {
        printf("%d\n",a[i]);
    }
    
}
void main()
{
    MergeSort();
}

